/*****************************************************************************
* Keppe Messenger (KMP) Keppe Project-Team User Messaging System
* Copyright (C) 2013-2014 Keppe Project-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

#ifndef KMSGFW111Q_H
#define KMSGFW111Q_H
#include <QString>
#include <QSslError>
#include <QSslSocket>
#include <QNetworkReply>
#include "KMsgFw_shared.h"

class KMSGFWSHARED_EXPORT KMsgFw111Q : public QObject
{
    Q_OBJECT

public:
    KMsgFw111Q(QObject *parent = 0);
    int loginUser(QString username, QString password);
    int logoutUser();
    bool isLoggedIn();
    bool requestGetUserContacts();
    bool requestGetUserContactsLength();
    bool requestGetUserContactsRequests();
    bool requestGetUserContactsWithAvatar();
    bool requestGetUserContactsWithStates();
    bool requestGetUserFriendRequests();
    bool requestGetUserFriendRequestsLength();
    bool actionAddUserContact(QString username);
    bool actionDelUserContact(QString username);
    bool actionRemoveUserContact(QString username);
    bool requestGetAnotherUserOnlineState(QString username);
    bool requestGetUserOnlineState();
    bool actionSetUserOnlineState(int state);
    bool requestGetAnotherUserMessageState(QString username);
    bool requestGetUserMessageState();
    bool actionSetUserMessageState(QString message);
    bool requestGetAnotherUserAvatar(QString username);
    bool requestGetUserAvatar();
    bool actionSetUserAvatar(QString base64, QString format);
    bool requestGetAnotherUserNick(QString username);
    bool requestGetUserNick();
    bool actionSetUserNick(QString nick);
    bool requestGetAnotherUserMail(QString username);
    bool requestGetUserMail();
    bool actionSetUserMail(QString mail, bool vfo);
    bool actionSetUserPassword(QString oldpassword, QString newpassword);
    bool requestGetUserProfileInfo(QString username);
    bool actionSendPokeToUser(QString username);
    bool actionSendMessageToUser(QString username, QString message, int id=-1);
    QString getUserContacts();
    QString getUserContactsLength();
    QString getUserContactsRequests();
    QString getUserContactsWithStates();
    QString getUserFriendRequests();
    QString getUserFriendRequestsLength();
    int addUserContact(QString username);
    int delUserContact(QString username);
    int removeUserContact(QString username);
    int getAnotherUserOnlineState(QString username);
    int getUserOnlineState();
    int setUserOnlineState(int state);
    QString getAnotherUserMessageState(QString username);
    QString getUserMessageState();
    int setUserMessageState(QString message);
    QString getAnotherUserNick(QString username);
    QString getUserNick();
    int setUserNick(QString nick);
    QString getUserAvatar();
    QString getAnotherUserMail(QString username);
    QString getUserMail();
    int setUserMail(QString mail, bool vfo);
    int setUserPassword(QString oldpassword, QString newpassword);
    QString getUserProfileInfo(QString username);
    int sendPokeToUser(QString username);
    int sendMessageToUser(QString username, QString message);
    bool isObjectIncoming();
    QString readObject();
    QString getClassVersion();
    QNetworkReply* downloadAvatar(QString avatar, bool overTLS = false);
    QNetworkReply* downloadAvatarHash(QString avatar, bool overTLS = false);
    bool uploadAvatar(QString username, QString password, QImage avatar);

signals:
    void objectIncomed(QString object);

private:
    QString workWithObjectWithEmit(QByteArray readed);
    QString workWithObject(QByteArray readed);
    QList<QSslError> sslErrors;
    QSslSocket *tcpSocket;
    QString system;
    bool loggedIn;
};

#endif // KMSGFW111Q_H
